package com.xtsoft.platform.task.controller;


import com.fasterxml.jackson.databind.JsonMappingException;
import com.xtsoft.core.controller.GenericController;
import com.xtsoft.core.repository.QueryFilter;
import com.xtsoft.core.repository.QueryResult;
import com.xtsoft.core.utils.ResultMsg;

import com.xtsoft.platform.base.system.domain.SysUser;
import com.xtsoft.platform.globe.utils.SecurityUtils;
import com.xtsoft.platform.task.domain.TaskBugTwo;
import com.xtsoft.platform.task.service.TaskBugTwoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.json.JsonParseException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.net.URISyntaxException;
import java.text.ParseException;

import static org.springframework.messaging.simp.SimpMessageHeaderAccessor.getUser;

/**
 * 
 * @ClassName:  taskBug   
 * <p> 任务缺陷处理类 </p>
 * @author: Codegen-代码生成器
 * @date:   2019年12月3日 上午10:59:46
 */
 @Tag(name = "任务缺陷2--处理接口")
@RestController
public class TaskBugTwoController2 extends GenericController{
	
	private final Logger log = LoggerFactory.getLogger(TaskBugTwoController2.class);
	
	@Autowired	
	private TaskBugTwoService taskBugService;


    /**
	 *   <p>查询任务缺陷列表，若分页，则页码信息在Request的参数中，包括当前页，每页记录数</p>
     * @return ResponseEntity<QueryResult<taskBug>>，json格式
     * @throws URISyntaxException 如果出错，则产生页码信息的 HTTP headers
	 * @author Codegen-代码生成器
	 * @date 2020-07-16 12:10:57
     */
    @GetMapping("/taskBugTwo/getAll")
	@Operation(summary = "查询，根据传递的条件查询任务缺陷列表，条件参数在Request中")
    public ResponseEntity<ResultMsg> getAll()
        throws URISyntaxException, JsonParseException, JsonMappingException, IOException, ParseException {
		SysUser user = (SysUser) SecurityUtils.getLoginedUser();
		log.info("获取任务缺陷列表开始......",  user.getLoginId(), user.getUsername(), getClientIp());
        QueryFilter<TaskBugTwo> filter=new QueryFilter<TaskBugTwo>(TaskBugTwo.class);
        filter.addFilterFromRequest(request);
        QueryResult<TaskBugTwo> result= taskBugService.anyQuery(filter);
		if(null == result || null == result.getResultList() || result.getResultList().size() < 0){
			log.info("获取任务缺陷列表失败",  user.getLoginId(), user.getUsername(), getClientIp());
			return new ResponseEntity<ResultMsg>(new ResultMsg(false,"获取任务缺陷列表失败"),HttpStatus.OK);
		}
		log.info("获取任务缺陷列表成功",  user.getLoginId(), user.getUsername(), getClientIp());	
        return new ResponseEntity<ResultMsg>(new ResultMsg(true,"获取列表成功",result.getResultList()),HttpStatus.OK);
    }
}
